var Startstop = function() {
	var initCheckbox = function() {
		$
				.ajax({
					type : "GET",
					cache : false,
					url : "startstop/list?sblx=" + $("input[name=sblx]").val() + "&orgcode="
							+ $("input[name=orgcode]").val() + "&storehousecode="
							+ $("input[name=storehousecode]").val(),
					success : function(responseJson) {
						if (responseJson.success == true) {// 返回true
							var data = responseJson.obj;
							var count = data.count;
							if ($("input[name=sblx]").val() == "1") {
								$("#startstopView")
										.append(
												$("<div class=\"checkbox col-md-6\"><label><input type=\"checkbox\" name=\"neihuanliu"
														+ "\">内环流" + "(" + eval("data.openstatue") + ")</label></div>"));
							}
							if ($("input[name=sblx]").val() == "2") {
								for (var i = 1; i <= count; i++) {
									$("#startstopView")
											.append(
													$("<div class=\"checkbox col-md-6\"><label><input type=\"checkbox\" name=\"fanstatus_"
															+ i
															+ "\">空调"
															+ i
															+ "("
															+ eval("data.fanstatus_" + i)
															+ ")</label></div>"));
								}
							}
							if ($("input[name=sblx]").val() == "3") {
								for (var i = 1; i <= count; i++) {
									$("#startstopView")
											.append(
													$("<div class=\"checkbox col-md-6\"><label><input type=\"checkbox\" name=\""
															+ eval("data.aerationtyep_" + i)
															+ "\">"
															+ eval("data.aerationtyep_" + i)
															+ ""
															+ "("
															+ eval("data.aerationstatus_" + i)
															+ "状态"
															+ ")</label></div>"));
								}
							}

						} else {
							QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
					}
				});
	}

	/**
	 * 增加页面事件绑定
	 */
	var addEventHandler = function() {
		$("#addBtn").on("click", function() {
			if ($("input[name=sblx]").val() == "1") {
				if ($("input[name=mode]").val() == "start") {
					var info = "1";
					$("input[name=controlinfo]").val(info);
					NeihuanliuCfxq.start();
				} else if ($("input[name=mode]").val() == "stop") {
					var info = "0";
					$("input[name=controlinfo]").val(info);
					NeihuanliuCfxq.stop();
				}
			} else if ($("input[name=sblx]").val() == "2") {
				if ($("input[name=mode]").val() == "start") {
					var info = "";
					$("#startstopView").find("input[type=checkbox]").each(function() {
						if (this.checked == true) {
							info = info + this.name.split("_")[1] + ":" + 1 + ";";
							KtkzCfxq.start($("input[name=storehousecode]").val(),this.name.split("_")[1]);
						}
					});
					$("input[name=controlinfo]").val(info);
				} else if ($("input[name=mode]").val() == "stop") {
					var info = "";
					$("#startstopView").find("input[type=checkbox]").each(function() {
						if (this.checked == true) {
							info = info + this.name.split("_")[1] + ":" + 0 + ";";
							KtkzCfxq.stop($("input[name=storehousecode]").val(),this.name.split("_")[1]);
						}
					});
					$("input[name=controlinfo]").val(info);
				}
			} else if ($("input[name=sblx]").val() == "3") {
				if ($("input[name=mode]").val() == "start") {
					var info = "";
					$("#startstopView").find("input[type=checkbox]").each(function() {
						if (this.checked == true) {
							info = info + this.name + ":" + 1 + ";";
							TongfengCfxq.start($("input[name=storehousecode]").val(),this.name);
						}
					});
					$("input[name=controlinfo]").val(info);
				} else if ($("input[name=mode]").val() == "stop") {
					var info = "";
					$("#startstopView").find("input[type=checkbox]").each(function() {
						if (this.checked == true) {
							info = info + this.name + ":" + 0 + ";";
							TongfengCfxq.stop($("input[name=storehousecode]").val(),this.name);
						}
					});
					$("input[name=controlinfo]").val(info);
				}
			}

			$.ajax({
				type : "POST",
				cache : false,
				url : "startstop/save",
				data : $("#addForm").serialize(),
				success : function(responseJson) {
					if (responseJson.success == true) {
						QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "success");
						layer.close(layer.index);
					} else {
						QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
					}
				}
			});
		});
		$("#cancelBtn").on("click", function() {
			layer.close(layer.index)
		});
	}
	return {
		init : function() {
			addEventHandler();
			initCheckbox();
		}
	}
}();

jQuery(document).ready(function() {
	Startstop.init();
});